package com.bajiao.common.api.vo;


import com.bajiao.common.menu.ResultEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @Description: 类
 * @Author: FanJq
 * @Date: 2024-10-10
 * @Version: V1.0
 */
@Data
public class RestResult<T> {

    private static final long serialVersionUID = 1L;

    // http 状态码
    @ApiModelProperty(value = "返回代码")
    private int code;

    // 返回信息
    @ApiModelProperty(value = "返回信息")
    private String msg;

    // 返回时间戳
    @ApiModelProperty(value = "时间戳")
    private String time = String.valueOf(System.currentTimeMillis());

    // 返回的数据
    @ApiModelProperty(value = "返回数据对象")
    private T data;


    public RestResult() {
    }

    public RestResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static RestResult<Object> success() {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = ResultEnum.OPERATION_SUCCESS.getDesc();
        restResult.code = ResultEnum.OPERATION_SUCCESS.getValue();
        restResult.data = null;
        return restResult;
    }

    public static RestResult<Object> success(String msg) {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = msg;
        restResult.code = ResultEnum.OPERATION_SUCCESS.getValue();
        restResult.data = null;
        return restResult;
    }

    public static RestResult<Object> success(Object data) {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = ResultEnum.OPERATION_SUCCESS.getDesc();
        restResult.code = ResultEnum.OPERATION_SUCCESS.getValue();
        restResult.data = data;
        return restResult;
    }


    public static RestResult<Object> success(Object data,String msg, Integer code) {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = ResultEnum.OPERATION_SUCCESS.getDesc();
        restResult.code = code;
        restResult.data = data;
        return restResult;
    }

    public static RestResult<Object> success(String msg, Object data) {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = msg;
        restResult.code = ResultEnum.OPERATION_SUCCESS.getValue();
        restResult.data = data;
        return restResult;
    }

    public static RestResult<Object> error() {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = ResultEnum.ERROR.getDesc();
        restResult.code = ResultEnum.ERROR.getValue();
        restResult.data = null;
        return restResult;
    }

    public static RestResult<Object> fail() {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = ResultEnum.OPERATION_FAIL.getDesc();
        restResult.code = ResultEnum.OPERATION_FAIL.getValue();
        restResult.data = null;
        return restResult;
    }

    public static RestResult<Object> fail(String msg) {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = msg;
        restResult.code = ResultEnum.ERROR.getValue();
        restResult.data = null;
        return restResult;
    }

    public static RestResult<Object> tokenOverdue() {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = ResultEnum.TOKEN_OVERDUE.getDesc();
        restResult.code = ResultEnum.TOKEN_OVERDUE.getValue();
        restResult.data = null;
        return restResult;
    }

    public static RestResult<Object> parameterMissing() {
        RestResult<Object> restResult = new RestResult<>();
        restResult.msg = ResultEnum.PARAMETER_MISSING.getDesc();
        restResult.code = ResultEnum.PARAMETER_MISSING.getValue();
        restResult.data = null;
        return restResult;
    }


}
